<template>
  <div class="add-form">
    <el-dialog
      :title="`${text}标签`"
      :visible="showTagedialog"
      width="400px"
      @close="bntCancel"
    >
      <el-form
        ref="dataForm"
        :rules="rules"
        :model="formdata"
        label-width="80px"
        style="width: 350px"
      >
        <!-- 所属学科 -->
        <el-form-item v-show="subjectid?false:true" label="所属学科" prop="subjectID">
          <el-select
            v-model="formdata.subjectID"
            style="width:100%"
            placeholder="请选择"
          >
            <el-option
              v-for="item in sympleDate"
              :key="item.value"
              :value="item.value"
              :label="item.label"
            />
          </el-select>
        </el-form-item>
        <!-- 目录名称 -->
        <el-form-item label="标签名称" prop="tagName">
          <el-input v-model="formdata.tagName" placeholder="请输入标签名称" />
        </el-form-item>
      </el-form>
      <!-- 确认和取消 -->
      <div slot="footer" class="dialog-footer">
        <el-row type="flex" justify="center">
          <el-button @click="bntCancel">{{ $t('table.cancel') }}</el-button>
          <el-button type="primary" @click="createData">{{ $t('table.confirm') }}</el-button>
        </el-row>
      </div>
    </el-dialog>
  </div>
</template>

<script>

export default {
  name: 'TageAdd',
  props: {
    showTagedialog: {
      type: Boolean,
      default: false
    },
    sympleDate: {
      type: Array,
      require: true
    },
    subjectid: {
     require: true
    }
  },
  data() {
    return {
      text: '',
      formdata: {
        subjectID: '',
        tagName: '',
        id: null
      },
      subjects: [],
      rules: {
        subjectName: [{ required: true, message: '请选择所属学科', trigger: 'blur' }],
        tagName: [{ required: true, message: '请选择标签名称', trigger: 'blur' }]
      }
    }
  },

  methods: {
    // 取消
    bntCancel() {
      this.$refs.dataForm.resetFields()
      this.formdata = {
        subjectID: '',
        tagName: '',
        id: ''
      }
      this.$emit('update:showTagedialog', false)
    },
    // 确认
    createData() {
      this.$refs.dataForm.validate(async isok => {
        if (isok) {
          this.$emit('addSub', this.formdata)// 通知父组件更新信息
        }
      })
    }
  }
}
</script>

<style scoped lang='less'></style>
